/**
 * Project  : Looker
 * Package  : net.freestu.looker.common
 * File     : News.java
 * Author   : solosky < solosky772@qq.com >
 * Date     : Jul 29, 2009
 * Modified : Jul 29, 2009
 * License  : Apache License 2.0 
 */
package net.freestu.looker.common;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import net.freestu.looker.util.HashUtils;
import net.freestu.looker.util.MD5;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.log4j.Logger;

/**
 *  新闻对象类
 *  保存了完整的新闻信息
 * @author  solosky
 * @version v1.0
 */
public class NewsEntity extends NewsMeta
{
	/**
	 * 新闻标题
	 */
	private String title;
	
	/**
	 * 新闻作者
	 */
	private String author;
	
	/**
	 * 新闻添加时间
	 */
	private Date  date;
	
	/**
	 * 新闻正文
	 */
	private String content;
	
	/**
	 * 新闻附件列表
	 */
	private ArrayList<Media> mediaList;
	
	/**
	 * 新闻原始HTML
	 */
	private String html;
	
	/**
	 * 新闻tag
	 */
	private String tag;
	
	/**
	 * 构造函数
	 */
	public NewsEntity()
	{
		this.mediaList = new ArrayList<Media>();
	}
	
	//////////////////////////////////////
	//getter && setter
	
	public String getTitle()
    {
    	return title;
    }

	public void setTitle(String title)
    {
    	this.title = title;
    }

	public String getAuthor()
    {
    	return author;
    }

	public void setAuthor(String author)
    {
    	this.author = author;
    }

	public Date getDate()
    {
    	return date;
    }

	public void setDate(Date date)
    {
    	this.date = date;
    }

	public String getContent()
    {
    	return content;
    }

	public void setContent(String content)
    {
    	this.content = content;
    	this.signature = HashUtils.fullHash(content);
    }

	
	public ArrayList<Media> getMediaList()
    {
    	return mediaList;
    }

	public void setMediaList(ArrayList<Media> mediaList)
    {
    	this.mediaList = mediaList;
    }

	public String getHtml()
    {
    	return html;
    }

	public void setHtml(String html)
    {
    	this.html = html;
    }

	public String getTag()
    {
    	return tag;
    }

	public void setTag(String tag)
    {
    	this.tag = tag;
    }

	/**
	 * 转化为NewsMeta
	 * @return
	 */
	public NewsMeta toNewsMeta()
	{
		if(this.mediaHashList==null)
			this.mediaHashList = new ArrayList<String>();
		//把附件列表里的附件编号放进NewsMeta里面的mediaHashList
		Iterator<Media> it = this.mediaList.iterator();
		while (it.hasNext()) {
			this.mediaHashList.add(it.next().getHash());
		}
		this.signature = MD5.calcMD5(this.content);
		return this;
	}
	
	////////////////////////
	/**
	 * toString
	 */
	public String toString()
	{
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
					.append("title",this.title)
					.append("url",this.url)
					.append("date",this.date)
					.append("medias",this.mediaList.size())
					.toString();
	}

	public static void main(String args[])
	{
		NewsEntity news = new NewsEntity();
		news.setTitle("哈哈哈哈");
		news.setDate(new Date());
		news.setUrl("http:///wwww");
		System.out.println(news);
		//
		Logger logger = Logger.getLogger(NewsEntity.class);
		logger.debug("jjajajaa");
		logger.error("ssss");
	}
}
